package com.aiguigu.LeCood;

import java.util.Arrays;
import java.util.Comparator;

public class LargesNumber {
    public static void main(String[] args) {
          int [] numbers = new int[]{93,56,10,23};
        String s = larNumbers(numbers);
        System.out.println(s);

    }

    public static String larNumbers(int [] nums){
        int length = nums.length;
        String[] strings = new String[length];

        for (int i = 0; i <length ; i++) {
            strings[i] = String.valueOf(nums[i]);
        }

        Arrays.sort(strings, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return (o2+o1).compareTo(o1+o2);
            }
        });
        StringBuilder stringBuilder = new StringBuilder();

        for (String s:strings){
            stringBuilder.append(s);
        }

        String ans = stringBuilder.toString();
        int startIndex = 0;

        for (int i=0;i<ans.length()-1;i++,startIndex++){
            if (ans.charAt(i)!= '0'){
                break;
            }
        }

        return ans.substring(startIndex);
    }
}
